import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { MarketFansService } from '@core/routes-services/market-fans.service';
import { ActivatedRoute, Params, Router } from '@angular/router';

@Component({
  selector: 'app-market-fans-business-detail',
  templateUrl: './market-fans-business-detail.component.html',
})
export class MarketFansBusinessDetailComponent implements OnInit {
  id: any = 0;
  entity: any = {};
  isLoading: boolean = false;

  constructor(private marketFansService: MarketFansService,
              private router: Router,
              private route: ActivatedRoute,
              public message: NzMessageService,) {
  }

  ngOnInit(): void {
    this.route.queryParams.forEach((params: Params) => {
      this.id = +params['id'];
      this.initEntity();
    });
  }

  initEntity() {
    if (this.id != 0) {
      this.isLoading = true;
      this.marketFansService.detail(this.id).then((res) => {
        if (res.status.toString().startsWith('20')) {
          this.entity = res.data;
        } else {
          this.message.warning(res.message);
        }
        this.isLoading = false;
      }, error => {
        this.message.error(error.message ? error.message : error.error);
        this.isLoading = false;
      });
    }
  }

}
